/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyDataContainer;

import java.util.ArrayList;
import java.util.Arrays;
import StringJoinerCutter.StringJoinerCutter;
/**
 *
 * @author Welcome
 */
public class MyDataString {
    
    //<editor-fold defaultstate="collapsed" desc="1/Danh sach thuoc tinh">
    private ArrayList<String> data;
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="2/Cac phuong thuc khoi tao">
    public MyDataString()
    {
        data = new ArrayList<String>();
    }
    
    public MyDataString(ArrayList<String> _data)
    {
        data = new ArrayList<String>(_data);
    }
    public MyDataString(MyDataString myData)
    {
        data = new ArrayList<String>(myData.data);
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="3/Getter/Setter">
    public ArrayList<String> getData() {
        return data;
    }
    
    /**
     * Set mảng các String vào data
     * @param data 
     */
    public void setData(ArrayList<String> data) {
        this.data = data;
    }
    
    public void setData(String[] strs)
    {
        for(int i=0; i<strs.length;i++)
            this.data.add(strs[i].trim());
    }
    
    /**
     * Set 1 string dạng abc,def,xyz,... vào data
     * @param str 
     */
    public void setData(String str)
    {
        ArrayList<String> temp = StringJoinerCutter.cutStringIntoStringList(str);
        setData(temp);
    }
    
    public String[] getAllData()
    {
        String[] result = new String[data.size()];
        for(int i=0; i<data.size();i++)
        {
            result[i] = data.get(i);
        }
        
        return result;
    }
    
    public String joinStringListToString()
    {
        return StringJoinerCutter.joinStringListToString(data);
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="4/Cac phuong thuc nghiep vu">
    public int getSize()
    {
        return data.size();
    }
    
    /**
     * Lấy vị trí content trong mảng
     * @param String content
     * @return index vị trí content trong mảng
     */
    public int getPosition(String content)
    {
        content=content.toLowerCase();
        for(int i=0;i<data.size();i++)
        {
            String temp = data.get(i).toLowerCase();
            if(temp.indexOf(content)>-1)
                return i;
        }
        return -1;
    }
    
    /**
     * Lấy chuỗi tại vị trí index
     * @param index
     * @return String
     */
    public String getAt(int index)
    {
        return data.get(index);
    }
    
    public void addContent(String content)
    {
        data.add(content);
    }
    public void addContent(MyDataString content)
    {
        for(int i=0;i<content.getSize();i++)
        {
            data.add(content.getAt(i));
        }
    }
    
    public void setContentAt(int index, String content)
    {
        data.set(index, content);
    }
    
    public void clearAll()
    {
        data.clear();
    }
    
    public void showData()
    {
        for(int i=0;i<data.size();i++)
            System.out.print(data.get(i)+" ");
        
        System.out.println();
    }
    
    public boolean isEqualWith(MyDataString myData)
    {
        if(data.size() !=myData.getSize())
            return false;
        
        boolean flag = true;
        for(int i=0;i<data.size();i++)
        {
            if(!data.get(i).equals(myData.getAt(i)))
            {
                return false;
            }
        }
        return flag;
    }
    //</editor-fold>

    
}
